package cn.hgd11.security.mapper;

import cn.hgd11.security.entity.SysUser;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * <p>
 * 用户信息表 Mapper 接口
 * </p>
 *
 * @author kaige.wang
 * @since 2022-03-10
 */
public interface SysUserMapper extends BaseMapper<SysUser> {

    /**
     * 按用户名获取用户信息
     * @param username
     * @return
     */
    default SysUser selectByUsername(String username) {
        List<SysUser> sysUsers = selectList(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, username).eq(SysUser::getDeleted, "0"));
        if (!CollectionUtils.isEmpty(sysUsers)) {
            return sysUsers.get(0);
        }

        return null;
    }
}
